import {defineConfig} from 'vite'
import {createVuePlugin} from 'vite-plugin-vue2'
import {resolve} from 'path'

export default defineConfig({
  server: {
    open: true,
  },
  build: {
    target: 'esnext',
    lib: {
      entry: resolve(__dirname, 'out/index.ts'),
      name: 'LsVue2Pro',
      fileName: (format) => `lsVue2Pro.${format}.js`,
      formats: ['es', 'umd'],
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ['vue', 'axios', 'element-ui', 'vue-router', 'qs', 'gsap'],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: 'Vue',
          axios: 'axios',
          'element-ui': 'ELEMENT',
          'vue-router': 'VueRouter',
          qs: 'Qs',
          gsap: 'gsap'
        }
      }
    },
    brotliSize: false
  },
  plugins: [createVuePlugin()]
})
